import { purchaseGiftAllFree } from '../../../api/user';
import { getSceneInfo } from '../../../api/scene';
import { wxPay } from '../../../api/pay';
import { showWxToast, timeoutTask } from '../../../utils/index';

Page({
  data: {
    isOpen: false,
    splid: '',
  },
  onLoad(options) {
    this.setData({
      splid: options.splid,
    });
    this.getSceneInfo();
  },
  onShow() {},
  exit() {
    wx.navigateBack({
      delta: 1,
    });
  },
  purchaseGiftAllFree() {
    purchaseGiftAllFree({
      splid: this.data.splid,
    })
      .then(res => {
        return wxPay(res);
      })
      .then(res2 => {
        ;
        showWxToast('支付成功!');
        this.setData({
          isOpen: true,
        });
      })
      .catch(err => {
        ;
        showWxToast('支付失败!');
      });
  },
  getSceneInfo() {
    getSceneInfo({ splid: this.data.splid })
      .then(res => {
        ;
        this.setData({
          isOpen: res.data.is_free_send_gift === '1'
        });
      })
      .catch(err => {
        ;
      });
  },
});
